<template>
    <div>
        <div>
        <van-nav-bar  class="db" title="购物车" @click-left="onClickLeft" fixed placeholder left-arrow>
        <template #right>
        <van-icon name="search" size="18" />
        </template>
        </van-nav-bar>
        </div>
<van-card v-for="(item,i) in game" :key="i"  style="border-bottom:1px solid rgba(1,1,1,0.1);"
 
  :price=item.gprice
  :desc=item.gjs
  :title=item.gname
  :thumb=item.gimg
>
  <template #tags>
    <van-tag  plain type="danger">{{item.gtag1}}</van-tag>
    <van-tag  plain type="danger">{{item.gtag2}}</van-tag>
    <van-tag  plain type="danger">{{item.gtag3}}</van-tag>
  </template>
  <template #footer>
    <van-button :id=item.gprice @click="mai" type="primary" size="small">购买</van-button>
    <van-button :id=item.gid @click="not" type="danger" size="small">取消</van-button>
  </template>
  </van-card>
  <van-submit-bar :price="price*100" button-text="提交订单" @submit="onSubmit" />
    </div>
</template>
<style scoped>
span{
    color: black;
}

</style>
<script>
import LogVue from './Log.vue';
export default {
    data() {
        return {
            game:'',
            date:'',
            price:0,
   
        }
    },
 
        methods:{
            onSubmit(){
                
            },
        onClickLeft(){
            this.$router.back(-1)
        },
        not(e){
            let id=e.target.id;

            console.log(`${id}`);
            this.axios.get(`/delete?gid=${id}`).then(result=>{

                            this.axios.get('/goshop').then(result=>{
this.$store.commit('spnum',result.data.result.length)
sessionStorage.setItem('gnum',result.data.result.length)

            })
        this.axios.get('/goshop').then((result)=>{
        this.game=result.data.result;   
        this.price=0
                         for (let i = 0; i < this.game.length; i++) {
                    // console.log(this.game[i].gprice);
                    this.price+=parseInt(this.game[i].gprice)
                    
                    
                }
            })
            })

        },
        mai(e){

            let price=e.target.id;
            this.$store.commit('buy',price)
sessionStorage.setItem('gm',price)

            this.$router.push(`/zf`)
        }

    },
            mounted(){
            this.axios.get('/goshop').then((result)=>{

                this.game=result.data.result;
                
                for (let i = 0; i < this.game.length; i++) {
                    // console.log(this.game[i].gprice);
                    this.price+=parseInt(this.game[i].gprice)
                    
                }

                
            })
        }
}
</script>